<template>
  <el-dialog :append-to-body="true" :visible.sync="dialog" :title="isAdd ? '新增' : '编辑'" width="600px">
    <el-form ref="form" :inline="true" :model="form" :rules="rules" size="small" label-width="80px">
      <el-form-item   label=" 记录ID号">
        <el-input v-model="form.did"  class="form_input" prop="did"/>
      </el-form-item>
      <el-form-item   label="工号">
        <el-input v-model="form.workId"  class="form_input" prop="workId"/>
      </el-form-item>
      <el-form-item   label="访问时间">
        <el-input v-model="form.passTime"  class="form_input" prop="passTime"/>
      </el-form-item>
      <el-form-item   label="状态">
        <el-input v-model="form.passStatus"  class="form_input" prop="passStatus"/>
      </el-form-item>
      <el-form-item   label="设备ID">
        <el-input v-model="form.deviceId"  class="form_input" prop="deviceId"/>
      </el-form-item>
      <el-form-item   label="createTime">
        <el-input v-model="form.createTime"  class="form_input" prop="createTime"/>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="text" @click="cancel">取消</el-button>
      <el-button :loading="loading" type="primary" @click="doSubmit">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { add, edit } from '@/api/workerAttendance'
export default {
  props: {
    isAdd: {
      type: Boolean,
      required: true
    },
    sup_this: {
      type: Object,
      default: null
    },
    dict: {
        type: Object,
        required: true
    }
  },
  data() {
    return {
      loading: false, dialog: false,
      form: {
        id: '',
        did: '',
        workId: '',
        passTime: '',
        passStatus: '',
        deviceId: '',
        createTime: ''
      },
      rules:{

      }
    }
  },
  methods: {
    cancel() {
      this.resetForm()
    },
    doSubmit() {
      this.loading = true
      if (this.isAdd) {
        this.doAdd()
      } else this.doEdit()
    },
    doAdd() {
      add(this.form).then(res => {
        this.resetForm()
        this.$notify({
          title: '添加成功',
          type: 'success',
          duration: 2500
        })
        this.loading = false
        this.sup_this.init()
      }).catch(err => {
        this.loading = false
        console.log(err.response.data.message)
      })
    },
    doEdit() {
      edit(this.form).then(res => {
        this.resetForm()
        this.$notify({
          title: '修改成功',
          type: 'success',
          duration: 2500
        })
        this.loading = false
        this.sup_this.init()
      }).catch(err => {
        this.loading = false
        console.log(err.response.data.message)
      })
    },
    resetForm() {
      this.dialog = false
      this.$refs['form'].resetFields()
      this.form = {
        id: '',
        did: '',
        workId: '',
        passTime: '',
        passStatus: '',
        deviceId: '',
        createTime: ''
      }
    }
  }
}
</script>

<style scoped>
  .form_input {
      width: 180px;
  }

  .form_input_row {
      width: 455px;
  }
</style>
